/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.transportes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import pe.com.transportes.modelo.Bus;

/**
 *
 * @author z3phiroth
 */
public class BusDAO {

    public void insertarbus(Connection con,Bus c) throws SQLException{

    String sql ="insert into bus values (?,?,?,?,?,?)";
    PreparedStatement ps = con.prepareStatement(sql);


    System.out.println("codigo dao "+c.getCod_bus());

    ps.setString(1,c.getCod_bus());
        ps.setString(2,c.getPlaca());
        ps.setString(3, c.getMarca());
        ps.setString(4,c.getEstado());
                     ps.setInt(5,c.getNroasientos());
        ps.setString(6,c.getDescripcion());

    ps.executeUpdate();
    }
public Bus buscarbus(Connection con,int codigo) throws SQLException{
    Bus bean = new Bus();
  String sql = "select * from bus where cod_bus=?";

        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,codigo);

          ResultSet rs = ps.executeQuery();
        if(rs.next()){

          bean.setCod_bus(rs.getString(1));
        bean.setPlaca(rs.getString(2));
        bean.setMarca(rs.getString(3));
        bean.setEstado(rs.getString(4));
        bean.setDescripcion(rs.getString(5));
         bean.setNroasientos(rs.getInt(6));

        }
        return bean;


}














}
